package com.abahgat.suffixtree;


import java.io.*;

public class LongestCommonSubstringRunner {

    public static void main(String[] args) throws Exception{
        BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(new File(args[0]))));
        int numberOfString = Integer.parseInt(reader.readLine());
        GeneralizedSuffixTree tree = new GeneralizedSuffixTree();
        for (int i = 0; i< numberOfString; i++){
            tree.put(reader.readLine(), i);
        }
        String longestCommonSubstring = tree.getLongestCommonString();

        BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(new File(args[1]))));
        writer.write(longestCommonSubstring);

        reader.close();
        writer.close();;

    }

}
